package com.linkage.seapeak.utils;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetDialog;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.linkage.jz.bankruptcy.R;

import java.util.List;

public class MenuBottomSheetDialog extends BottomSheetDialog {

    Context context;
    LinearLayout content;

    public MenuBottomSheetDialog(@NonNull Context context) {
        super(context);
        init(context);
    }

    public MenuBottomSheetDialog(@NonNull Context context, int theme) {
        super(context, theme);
        init(context);
    }

    protected MenuBottomSheetDialog(@NonNull Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        init(context);
    }

    private void init(Context context) {
        this.context = context;
        setContentView(R.layout.view_dialog_menu);
        content = findViewById(R.id.linear);
    }

    /**
     * 设置项
     * @param itemList
     */
    public void setItemList(List<DialogMenuItem> itemList) {
        content.removeAllViews();
        for (int i = 0;i < itemList.size();i++) {
            DialogMenuItem item = itemList.get(i);
            addItem(item);
        }
    }

    public void addItem(DialogMenuItem item) {
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, CommonUtils.dp2px(context,50));
        params.bottomMargin = CommonUtils.dp2px(context,1);
        TextView itemView = new TextView(context);
        itemView.setText(item.menuName);
        itemView.setTextColor(item.menuColor);
        itemView.setTextSize(16);
        itemView.setGravity(Gravity.CENTER);
        itemView.setBackground(context.getResources().getDrawable(R.drawable.bg_default_button_selector));
        itemView.setOnClickListener(item.menuClick);
        content.addView(itemView, params);
    }

    public static class DialogMenuItem {

        String menuName;
        int menuColor;
        View.OnClickListener menuClick;

        public DialogMenuItem(String menuName, View.OnClickListener menuClick) {
            this.menuName = menuName;
            this.menuColor = 0xff289f9f;
            this.menuClick = menuClick;
        }

        public DialogMenuItem(String menuName, int menuColor, View.OnClickListener menuClick) {
            this.menuName = menuName;
            this.menuColor = menuColor;
            this.menuClick = menuClick;
        }
    }
}
